#include "person.h"
#include <iostream>
#include <cstring>

using namespace std;

namespace A {
    Person::Person() {
        cout << "Person()" << endl;
    };

    Person::Person(Person &per) {
        this->name = new char[strlen(per.name) + 1];
        strcpy(this->name, per.name);
    };

    Person::~Person() {
        cout << "~Person()" << endl;
        if (this->name) {
            delete this->name;
        }
    };

    Person::Person(char *name) {
        cout << "Person(char *name)" << endl;
        this->name = new char[strlen(name) + 1];
        strcpy(this->name, name);
    };

    Person::Person(char *name, int age) {
//        cout << "Person(char *name, int age)" << endl;
        cout << "name = " << name << ", age = " << age << endl;

        this->name = new char[strlen(name) + 1];
        strcpy(this->name, name);

        this->age = age;
    };

    void Person::setName(char *name) {
        cout << "Person::setName" << endl;
        if (this->name) {
            delete this->name;
        }
        this->name = new char[strlen(name) + 1];
        strcpy(this->name, name);
    }

    void Person::setAge(int age) {
        cout << "Person::setAge" << endl;
        this->age = age;
    }

    void Person::setWork(char *work) {
        this->work = work;
    }

    void Person::printInfo(void) {
        cout << "name = " << name << ", age = " << age << endl;
    }

    void printVersion(void) {
        printf("Person v1, by waylon\n");
    }
}